home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mc51bugs / q33368 < prev    next >
Text File  |  1988-08-09  |  2KB  |  59 lines

  1. Q33368 Incorrect Code with /Oal and Unsigned Chars in Loops
  2. C Compiler
  3. 5.10   | 5.10
  4. MS-DOS | OS/2
  5.  
  6. Summary:
  7.    When relaxed alias checking is used with loop optimization, errors
  8. may occur on arithmetic operations on unsigned chars. Turning off either
  9. loop optimization or relaxing alias checking and declaring the
  10. variables in question to unsigned short alleviates the problem.
  11.    Microsoft has confirmed this to be a problem in Version 5.10. We
  12. are researching this problem and will post new information as it
  13. becomes available.
  14.  
  15. More Information:
  16.    The following code should print the remainder multiplied by ten of
  17. each number entered. However, ProcessVar is erroneously always zero.
  18.    The following is a sample program:
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. int main (int argc, char *argv[]);     /* Function Prototypes */
  24.  
  25. int main (argc, argv)
  26. int    argc;
  27. char    *argv[];
  28. {
  29.        unsigned char TestVar;
  30.        unsigned char ProcessVar;
  31.        int           i;
  32.  
  33.    if(argc < 2)
  34.        printf("usage: %s <integer 1> <integer 2>...<integer n>\n",argv[0]);
  35.    else {
  36.        for (i = 1; i < argc; i++) {
  37.            TestVar = (unsigned char)atoi(argv[i]);
  38.            ProcessVar = (TestVar % 10) * 10;
  39.            printf("ProcessVar: %d\n",ProcessVar);
  40.            }
  41.        }
  42. return (0);
  43. }
  44.  
  45.    The incorrect assembly for the arithmetic operation is as follows:
  46.  
  47. ;|***                   ProcessVar = (TestVar % 10) * 10;
  48. ; Line 19
  49. *** 000045      2a e4                   sub     ah,ah
  50. *** 000047      8b c2                   mov     ax,dx
  51. *** 000049      d0 e2                   shl     dl,1
  52. *** 00004b      d0 e2                   shl     dl,1
  53. *** 00004d      02 d0                   add     dl,al
  54. *** 00004f      d0 e2                   shl     dl,1
  55. *** 000051      88 56 fe                mov     BYTE PTR [bp-2],dl
  56.  
  57. Keywords:  buglist5.10
  58. Updated  88/08/10 03:33
  59.